package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.query.SearcheObject;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService {

    @Autowired
    private TravelCommendMapper travelCommendMapper;


    @Override
    public PageInfo query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo queryForApp(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Map> list = travelCommendMapper.selectForAppList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if(travelCommend.getId()!=null){
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }else{
            travelCommendMapper.insert(travelCommend);
        }
    }

    @Override
    public PageInfo queryForSearchList(SearcheObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.selectForSearchList(qo);
        System.out.println(list);
        return new PageInfo(list);
    }

}
